from appium import webdriver
import time,traceback

desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '8.1.0'
desired_caps['deviceName'] = 'test'
# desired_caps['app'] = r'F:\apk\toutiao.apk'
desired_caps['appPackage'] = 'com.huawei.appmarket'
desired_caps['appActivity'] = 'com.huawei.appmarket.MainActivity'
desired_caps['unicodeKeyboard']  = True
desired_caps['resetKeyboard']  = True
desired_caps['noReset'] = True
desired_caps['newCommandTimeout'] = 6000
#启动Remote RPC
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

# ele=driver.find_element_by_id('com.huawei.appmarket:id/substance_layout')
# driver.find_element_by_id('com.huawei.appmarket:id/backPicture')

driver.open_notifications()
time.sleep(1)

# eles =driver.find_elements_by_xpath('//*[@resource-id="com.android.systemui:id/notification_stack_scroller"]/android.widget.FrameLayout')
# print(eles.text)

ele =driver.find_elements_by_xpath('//android.widget.ScrollView//android.view.View')
for eles in ele:
    print(eles.text)

driver.press_keycode(4)



# location1 = ele.location
# size1=ele.size
# print(location1,size1)
# x1=location1['x']+int(size1['width']*0.8)
# x2=location1['x']+int(size1['width']*0.2)
# y=location1['y']+int(size1['height']*0.5)
# for i in range(10):
#     driver.swipe(start_x=x1,start_y=y,end_x=x2,end_y=y,duration=500)
#     time.sleep(0.5)
#
# for i in range(10):
#     driver.swipe(start_x=900,start_y=500,end_x=200,end_y=500,duration=400)
#     time.sleep(0.5)